# GDIR define
GDIR=../..


# MACIPATH define
MACIPATH=$(GDIR)/MaCI


# External includes
include $(GDIR)/GIMI/Makefile.gimi
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile


# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES $(CE)
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
BUSPATH=$(MACIPATH)/bus
DRIVERPATH=$(MACIPATH)/drivers
MACIINTERFACEPATH=$(MACIPATH)/interfaces
INCLUDES=-I$(UTILSPATH) $(INCGIMI) \
	$(MACI_INCLUDE_PATHS) 
WFLAGSC=-Wall -Wunused -Wshadow
WFLAGSCPP=-Wall -Wunused -Wshadow -Weffc++
WFLAGSDCPP=
CFLAGS=-O0 -g3 $(WFLAGSC) $(INCLUDES) $(EXTRADEFS)
CPPFLAGS=-O0 -g3 $(WFLAGSCPP) $(INCLUDES) $(EXTRADEFS)
DCPPFLAGS=-O0 -g3 $(WFLAGSDCPP) $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=$(MACI_EXT_LIBRARIES) -lglut -lGLU -lrt -lpthread $(LIBSGIMI)

SRCSC=$(CGIMI)
SRCSCPP=$(CPPGIMI)
MACISRCSCPP=$(MACI_EXT_SRC_CPP) \
	    $(MACI_BASE_SRC_CPP) \
	    $(MACI_INTERFACE_DUMMY_COMMON_CPP) \
	    $(MACI_INTERFACE_DUMMYSERVER_CPP) 
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)
MACIOBJSCPP=$(MACISRCSCPP:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) $(LIBS) 

.PHONY: all

# Define targets
TARGETS=AC3DViewer

# All rule compiles all per default
all:	$(TARGETS)

###############################################
###############################################
AC3DVIEWER_OBJECTS=$(OBJSC) $(OBJSCPP) \
		    AC3DViewer.opp AC3DtoGL.opp
AC3DViewer: $(AC3DVIEWER_OBJECTS)
	@$(LINK) -o $@ $^
	@echo "      [LD] $@"
##############################################

###############################################
###############################################
.PHONY: clean maci-clean maciclean real-clean realclean
local-clean clean:
	@rm -f *.o *.opp *.dopp $(TARGETS)
	@echo "     [LOCAL-CLEAN]"

maci-clean maciclean: clean
	rm -f $(MACIOBJSCPP)
	@echo "     [MACI-CLEAN]"

real-clean realclean: maciclean
	rm -f $(OBJSC) $(OBJSCPP) \
	$(DUMMY_DUMMY_OBJECTS) 
	@echo "     [REAL-CLEAN]"

########### Compile rules ####################
# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

# Compile rule for all .dopp (dirty .cpp) files
%.dopp:	%.cpp
	@$(COMPILEDCPP) -o $@ $<
	@echo "      [DIRTY-CXX] $<"

##############################################
